import Cookies from 'js-cookie'

const state = {
  sidebar: {
    opened: true,
    withoutAnimation: false
  },
  device: 'desktop',
  loading:false,
  isNotIndex:true, // 是否不是首页
  routerActive:'1.1',
  isIndex:false,
  isLoading:false,
  showBtn:false
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = true
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', 1)
    } else {
      Cookies.set('sidebarStatus', 0)
    }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    Cookies.set('sidebarStatus', 0)
    state.sidebar.opened = false
    state.sidebar.withoutAnimation = withoutAnimation
  },
  SET_SHOW_BTN: (state, showBtn) => {
    state.showBtn = showBtn
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device
  },
  TOGGLE_LOADING: (state, loading) => {
    state.loading = loading
  },
  SET_ISNOT_INDEX: (state, isNotIndex) => {
    state.isNotIndex = isNotIndex
  },
  SET_INDEX: (state, isIndex) => {
    state.isIndex = isIndex
  },
  SET_ROUTER_ACTIVE: (state, routerActive) => {
    state.routerActive = routerActive
  },
  setLoading: (state, isLoading) => {
    state.isLoading = isLoading
    console.log(state.isLoading,'state.isLoading')
  },
}

const actions = {
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  closeSideBar({ commit }, { withoutAnimation }) {
    commit('CLOSE_SIDEBAR', withoutAnimation)
  },
  toggleDevice({ commit }, device) {
    commit('TOGGLE_DEVICE', device)
  },
  toggleLoading({ commit }, loading) {
    commit('TOGGLE_LOADING', loading)
  },
  setIsNotIndex({ commit }, isNotIndex) {
    commit('SET_ISNOT_INDEX', isNotIndex)
  },
  setIndex({ commit }, isIndex) {
    commit('SET_INDEX', isIndex)
  },
  setRouteActive({ commit }, routerActive) {
    commit('SET_ROUTER_ACTIVE', routerActive)
  },
  setShowBtn({ commit },showBtn) {
    commit('SET_SHOW_BTN', showBtn)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
